﻿
function SelectAll(parentControlId, selectorId, rowSelectorControlId) {

    var grid = $("#"+parentControlId);
    //var inputFields = grid.getElementsByTagName("input");
    var inputFields = $("input")
    for(var i=0;i<inputFields.length;i++)
    {
        if(inputFields[i].type == "checkbox")
        {
            //rowSelect is the id of the row selection checkbox
            var id = inputFields[i].id.toString();
            if(id.indexOf(rowSelectorControlId,0)>0)
                inputFields[i].checked = document.getElementById(selectorId).checked;
        }
    }
}

function ascii_value (c)
{
	// restrict input to a single character
	c = c . charAt (0);

	// loop through all possible ASCII values
	var i;
	for (i = 0; i < 256; ++ i)
	{
		// convert i into a 2-digit hex string
		var h = i . toString (16);
		if (h . length == 1)
			h = "0" + h;

		// insert a % character into the string
		h = "%" + h;

		// determine the character represented by the escape code
		h = unescape (h);

		// if the characters match, we've found the ASCII value
		if (h == c)
			break;
	}
	return i;
}

function isLeapYear(year)
{
    if(isNaN(year))
        return false;
        
    var leapYear = false;
    leapYear = ( ( ( year % 4 ) == 0 ) && ( ( year % 100 ) != 0 ) || ( ( year % 400 ) == 0 ) );
    return leapYear;
}

function clearText(field, initialText, restoreColor)
{
    if(field!= null)
    {
        if(field.value == initialText)
        {
            field.value = "";
            field.style.color = restoreColor;
        }
    }
}

function resetText(field, initialText, initialColor)
{
    if(field.value == "")
    {
        field.value = initialText;
        field.style.color = initialColor;
    }
}

function showObj(obj) {
    var obj = eval(obj);
    var str = '';
    for (prop in obj) {
        str += prop + ' : ' + obj[prop];
    }
    alert(str);
}